﻿#ifndef GLOBALINSTANCE_H
#define GLOBALINSTANCE_H

#include <QtGlobal>

template<class T>
class GlobalInstance
{
private:    
    Q_DISABLE_COPY(GlobalInstance)
    static T* global;
protected:
    GlobalInstance(){}
    ~GlobalInstance(){
        global = Q_NULLPTR;
    }
public:
    static T* instance()
    {
        if(!global)
            global = new T;
        return global;
    }
};

template <class T>
T* GlobalInstance<T>::global = Q_NULLPTR;

#endif // GLOBALINSTANCE_H
